package com.swift.authority.service.role.impl;

import com.swift.authority.core.role.dto.RoleDto;
import com.swift.authority.core.role.response.RoleRes;
import com.swift.authority.mapper.role.RoleMapper;
import com.swift.authority.service.role.RoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @description :
 * @date 2022/06/18 16:20
 * @since open jdk 1.8
 */
@Service
public class RoleServiceImpl implements RoleService {
    private Logger logger = LoggerFactory.getLogger(RoleServiceImpl.class);
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public RoleRes queryRoleInfoById(int rid) {
        logger.info("获取用户角色信息,rid:{}",rid);
        RoleDto roleDto = roleMapper.queryRoleInfoById(rid);
        RoleRes roleRes = new RoleRes();
        BeanUtils.copyProperties(roleDto,roleRes,RoleRes.class);
        return roleRes;
    }

    @Override
    public RoleRes queryRoleByUserName(String userName) {
        logger.info("获取用户角色,userName:{}",userName);
        RoleDto roleDto = roleMapper.queryRoleByUserName(userName);
        RoleRes roleRes = new RoleRes();
        BeanUtils.copyProperties(roleDto,roleRes,RoleRes.class);
        return roleRes;
    }
}
